//
// Created by haoy on 2017/6/20.
//

#include "rtp/rtp_map.hpp"

void RtpMap::add_back(const uint8_t pt, const int c) {
    // todo: fix me
    // this is just a workaround for firefox providing two payloads with same codec H264 and different parameters
    if (pt2c_.count(pt)) {
        return;
    }
    if (c2pt_.count(c)) {
        return;
    }
    pt2c_.emplace(pt, c);
    c2pt_.emplace(std::move(c), std::move(pt));
    codecs_.emplace_back(c);
}

uint8_t RtpMap::pt(const int c) const {
    auto it = c2pt_.find(c);
    if (it == c2pt_.end()) {
        return -1;
    }
    return it->second;
}

int RtpMap::codec(const uint8_t pt) const {
    auto it = pt2c_.find(pt);
    if (it == pt2c_.end()) {
        return -1;
    }
    return it->second;
}

std::list<int> RtpMap::codecs() const {
    return codecs_;
}

void RtpMap::setParameters(int c, const Parameters& p) {
    parameters_[c] = p;
}

RtpMap::Parameters RtpMap::parameters(int codec) const {
    auto it = parameters_.find(codec);
    if (it == parameters_.end()) {
        return RtpMap::Parameters();
    }
    return it->second;
}
